package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.cache.Java0409GmallCache;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ItemService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * projectName: gmall
 *
 * @author: 陈鹏
 * time: 2022/9/25 16:15 星期日
 * description: 商品详情页面使用的控制层
 */
@RestController
@RequestMapping("/api/item")
public class ItemController {

    @Resource
    private ItemService itemService;

    /**
     * 根据skuId查询skuInfo信息
     * @param skuId
     * @return
     */
    @GetMapping("/getSkuInfo/{skuId}")
    @Java0409GmallCache(prefix = "getSkuInfo:")
    public SkuInfo getSkuInfo(@PathVariable("skuId") Long skuId){
        return itemService.getSkuInfo(skuId);
    }


    /**
     * 根据category3Id查询分类信息
     * @param category3Id
     * @return
     */
    @GetMapping(value = "/getCategory/{category3Id}")
    @Java0409GmallCache(prefix = "getCategory:")
    public BaseCategoryView getCategory(@PathVariable("category3Id") Long category3Id){
        return itemService.getBaseCategory(category3Id);
    }

    /**
     * 根据skuId查询sku图片列表
     * @param skuId
     * @return
     */
    @GetMapping(value = "/getImageList/{skuId}")
    @Java0409GmallCache(prefix = "getImageList:")
    public List<SkuImage> getImageList(@PathVariable("skuId")Long skuId){
        return itemService.getImageList(skuId);
    }

    /**
     * 根据skuId查询商品价格
     * @param skuId
     * @return
     */
    @GetMapping(value = "/getPrice/{skuId}")
    @Java0409GmallCache(prefix = "getPrice:")
    public BigDecimal getPrice(@PathVariable("skuId")Long skuId){
        return itemService.getPrice(skuId);
    }

    /**
     * 根据sku和spu的id查询销售属性和值以及标识出当前的sku的值是哪些
     * @param skuId
     * @param spuId
     * @return
     */
    @GetMapping(value = "/getSpuSaleAttr/{skuId}/{spuId}")
    @Java0409GmallCache(prefix = "getSpuSaleAttr:")
    public List<SpuSaleAttr> getSpuSaleAttr(@PathVariable("skuId")Long skuId,
                                            @PathVariable("spuId")Long spuId){
        return itemService.getSpuSaleAttr(skuId,spuId);
    }

    /**
     * 根据spuId查询所有的销售属性和销售值
     * @param spuId
     * @return
     */
    @GetMapping(value = "/getSkuSaleAttrInfo/{spuId}")
    @Java0409GmallCache(prefix = "getSkuSaleAttrInfo:")
    public Map getSkuSaleAttrInfo(@PathVariable(value = "spuId")Long spuId){
        return itemService.selectSkuValuesList(spuId);

    }

    /**
     * 查询品牌详情
     * @param id
     * @return
     */
    @GetMapping(value = "/getBaseTrademark/{id}")
    public BaseTrademark getBaseTrademark(@PathVariable(value = "id") Long id){
        return itemService.getBaseTrademark(id);
    }

    /**
     * 根据skuId查询sku的平台属性
     * @param skuId
     * @return
     */
    @GetMapping(value = "/getBaseAttrInfoList/{skuId}")
    public List<BaseAttrInfo> getBaseAttrInfoList(@PathVariable(value = "skuId") Long skuId){
        return itemService.getBaseAttrInfo(skuId);
    }

    /**
     * 扣减库存
     * @param decountMap
     */
    @GetMapping(value = "/decount")
    public void decount(@RequestParam Map<String, Object> decountMap){
        itemService.decount(decountMap);
    }

    /**
     * 回滚库存
     * @param rollBackMap
     */
    @GetMapping(value = "/rollback")
    public void rollback(@RequestParam Map<String, Object> rollBackMap){
        itemService.rollback(rollBackMap);
    }
}
